﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_ShopInvoiceView : Admin, IRequiresSessionState
{
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TxtBeginDate.Attributes.Add("onclick", "SelectDate(" + this.TxtBeginDate.UniqueID + ",'yyyy-MM-dd');");
        this.TxtEndDate.Attributes.Add("onclick", "SelectDate(" + this.TxtEndDate.UniqueID + ",'yyyy-MM-dd');");
        if (!base.admin.CheckAdminPower(21))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Invoice");
            base.WriteRightErrMsg();
        }
    }
    protected void GridView2_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow gridViewRow in this.GridView2.Rows)
        {
            if (!base.admin.CheckAdminPower(21))
            {
                gridViewRow.Cells[10].Visible = false;
            }
            if (gridViewRow.Cells[1].Text != "")
            {
                gridViewRow.Cells[1].Text = DateTime.Parse(gridViewRow.Cells[1].Text).ToShortDateString();
            }
            if (gridViewRow.Cells[9].Text != "")
            {
                gridViewRow.Cells[9].Text = DateTime.Parse(gridViewRow.Cells[9].Text).ToShortDateString();
            }
            if (gridViewRow.Cells[2].Text.Trim() == "0")
            {
                gridViewRow.Cells[2].Text = "地税普通发票";
            }
            if (gridViewRow.Cells[2].Text.Trim() == "1")
            {
                gridViewRow.Cells[2].Text = "国税普通发票";
            }
            if (gridViewRow.Cells[2].Text.Trim() == "2")
            {
                gridViewRow.Cells[2].Text = "增值税发票";
            }
        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
    protected void Delete_ButtonOnClick(object sender, CommandEventArgs e)
    {
        if (base.admin.CheckAdminPower(21))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "Invoice");
            base.WriteRightErrMsg();
        }
        try
        {
            int.Parse(e.CommandName.ToString());
        }
        catch
        {
            this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
        }
        string text = e.CommandName.ToString();
        if (text != "")
        {
            Shop_InvoiceItem shop_InvoiceItem = new Shop_InvoiceItem(this.conn);
            shop_InvoiceItem.DeleteInvoice(text);
            this.GridView2.DataBind();
        }
    }
    protected void txtSalername_TextChanged(object sender, EventArgs e)
    {
        if (this.txtSalername.Text != "")
        {
            UserBll userBll = new UserBll();
            int userIDByUserName = userBll.GetUserIDByUserName(this.txtSalername.Text);
            if (userIDByUserName > 0)
            {
                foreach (ListItem listItem in this.DropDownList1.Items)
                {
                    if (listItem.Value == userIDByUserName.ToString())
                    {
                        this.txtSalername.Text = "";
                        return;
                    }
                }
                ListItem listItem2 = new ListItem();
                listItem2.Text = this.txtSalername.Text;
                listItem2.Value = userIDByUserName.ToString();
                this.DropDownList1.Items.Add(listItem2);
                this.DropDownList1.SelectedValue = userIDByUserName.ToString();
                this.txtSalername.Text = "";
            }
        }
    }
}
